/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	IShaderStage.cpp
*
*	Comments	-	See IShaderStage.h
*
**************************************************************************************/
#include "../Include/IShaderStage.h"
#include "../Include/ConstantBuffer.h"
#include "../Include/SamplerState.h"
#include "../Include/ShaderResource.h"

namespace Pulse
{
	IShaderStage::IShaderStage( void )
		: IPipelineStage( )
	{
		ClearStates();
	}

	IShaderStage::~IShaderStage( void )
	{

	}

	void IShaderStage::SetShader( Shader *pShader )
	{
		m_stateCache.m_pShader = pShader;
	}

	void IShaderStage::SetConstantBuffer( UINT slot, const ConstantBuffer *pConstantBuffer )
	{
		m_stateCache.m_pConstantBuffers[slot] = pConstantBuffer;
		m_stateCache.m_pD3DConstantBuffers[slot] = (const ID3D11Buffer*)(pConstantBuffer ? pConstantBuffer->GetNakedBuffer() : PSX_NULL);
	}

	void IShaderStage::SetSamplerState( UINT slot, const SamplerState *pSampler )
	{
		m_stateCache.m_pSamplerStates[slot] = pSampler;
		m_stateCache.m_pD3DSamplerStates[slot] = (const ID3D11SamplerState*)(pSampler ? pSampler->GetNakedSamplerState() : PSX_NULL);
	}

	void IShaderStage::SetShaderResource( UINT slot, const ShaderResource *pGraphicsResource )
	{
		m_stateCache.m_pShaderResources[slot] = pGraphicsResource;
		m_stateCache.m_pD3DShaderResources[slot] = (const ID3D11ShaderResourceView*)(pGraphicsResource ? pGraphicsResource->GetNakedShaderResource() : PSX_NULL);
	}

	void IShaderStage::SetUnordererdAccess( UINT slot, const ShaderResource *pGraphicsResource )
	{
		m_stateCache.m_pUnorderedAccessResources[slot] = pGraphicsResource;
		m_stateCache.m_pD3DUnorderedAccessViews[slot] = (const ID3D11UnorderedAccessView*)( pGraphicsResource? pGraphicsResource->GetNakedUnorderedAccessResource() : PSX_NULL);
	}

	void IShaderStage::ClearStates( void )
	{
		m_stateCache.ClearStates();
	}

	void IShaderStage::BindStates( void )
	{
		BindShader();
		BindConstantBuffers();
		BindShaderResourceViews();
		BindSamplerStates();
		BindUnordererdAccessViews();
	}

}